<?php

namespace App\Console\Commands;

use App\Models\goods\Order;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Console\Command;

class AutoCancel extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'auto:cancel';

    /**
     * 建议每5分钟执行一次
     *
     * 24小时未付款订单系统自动取消
     *
     * The console command description.
     *
     * @var string
     */
    protected $description = 'order auto confirm command';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        /* 永不超时 */
        ini_set('max_execution_time', 0);
        $map['status'] = 0;
        $map['order_group_id'] = 0;
        $map[] = ['created_at','<',Carbon::now()->subDay()];
        $orders = Order::where($map)->get();

        foreach ($orders as $order){
            if ($order instanceof Order);

            $order->status = -1;
            $order->save();
        }

    }


}
